<html>
<head><meta charset="utf-8"><title>Parametric Flycheck? · t-compiler/rust-analyzer · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/index.html">t-compiler/rust-analyzer</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Parametric.20Flycheck.3F.html">Parametric Flycheck?</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="207480877"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Parametric%20Flycheck%3F/near/207480877" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> woody77 <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Parametric.20Flycheck.3F.html#207480877">(Aug 20 2020 at 01:35)</a>:</h4>
<p>I'm looking at enabling the flycheck with a rust-project.json setup, and I think that I could make it work (by using a custom wrapper around cargo), if I had the name of the file that was saved that triggered the flycheck.  In VSCode, the tasks can receive arguments like <code>${fileDirname}</code>, which is the folder that contains the source file that's in the open editor.</p>
<p>Something similar to the flycheck would be useful, as then I could use the source file that was changed as a trigger for finding the "right" thing to run <code>cargo check</code> on.</p>
<p>Is there any reasonable way to plumb this through?</p>
<p>Further, I'm not seeing the flycheck results in my file (I'm hardcoding some things in a test setup).  And I think the issue is that the <code>cargo check</code> output is using relative paths (<code>src/lib.rs</code>), that aren't relative to the root of my overall workspace.  I assume this breaks RA's ability to line up the errors from <code>cargo check</code> with the open file in the editor?  (VSCode's <code>$rustc-watch</code> has the same issue).</p>



<a name="207504967"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Parametric%20Flycheck%3F/near/207504967" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Parametric.20Flycheck.3F.html#207504967">(Aug 20 2020 at 09:38)</a>:</h4>
<p><span class="user-mention" data-user-id="301314">@woody77</span> cargo wrapper is the wrong approach for your use-case, you need to use <code>rust-analyzer.checkOnSave.overrideCommand</code>.</p>



<a name="207505155"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Parametric%20Flycheck%3F/near/207505155" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Parametric.20Flycheck.3F.html#207505155">(Aug 20 2020 at 09:40)</a>:</h4>
<p>Or maybe I am misundestanding what do you mean by "cargo wrapper". But you shouldn't force bazel to look like Cargo. If there's anything cargo-specific in rust-analyzer, it's a bug in rust-analyzer. <code>overrideCommand</code> should allow you to plug arbitrary thing instead of cargo, which, in your case, should be something like "use bazel (or is it gn?) to compile the code passing <code>--error-format=json</code> to rustc".</p>



<a name="207505187"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Parametric%20Flycheck%3F/near/207505187" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Parametric.20Flycheck.3F.html#207505187">(Aug 20 2020 at 09:41)</a>:</h4>
<p>The question about "which changes trigger rebuild" is interesting. That's simply not implemented in rust-analyzer yet, we have a binary "there was a change" event.</p>



<a name="207543419"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Parametric%20Flycheck%3F/near/207543419" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> woody77 <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Parametric.20Flycheck.3F.html#207543419">(Aug 20 2020 at 16:31)</a>:</h4>
<p>I wasn't very clear, sorry about that.</p>
<p>I'm using the <code>overrideCommand</code> to run a script, which currently invokes <code>cargo check</code> using a generated Cargo.toml file that's not in the root of the project workspace (but about 4 levels deep).  From the shell, I can run the script manually, and see error output.  (this is a hard-coded test).</p>
<p>I'm not passing <code>-error-format=json</code> to rustc, so that's definitely part of my problem.  I'll see what that gets me.</p>
<p>Ideally, though, I'd like to be able to invoke just a portion of the build space (not every crate we have, since that's 1000s).  What I'd like to do is tell rustc/cargo to check the crate that corresponds to the file that was just saved by VSCode. </p>
<p>as an example, what my script is doing right now is:<br>
<code>cd some/path/that/is/hardcoded &amp;&amp; cargo check</code></p>
<p>I'd like that path to be based on the file with focus in the editor.</p>



<a name="207543663"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Parametric%20Flycheck%3F/near/207543663" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Parametric.20Flycheck.3F.html#207543663">(Aug 20 2020 at 16:32)</a>:</h4>
<p>Uhu. My advice would be to remove Cargo from the equation completely, just run whatever build system you use directly</p>



<a name="207544798"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Parametric%20Flycheck%3F/near/207544798" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Parametric.20Flycheck.3F.html#207544798">(Aug 20 2020 at 16:40)</a>:</h4>
<blockquote>
<p>I'd like that path to be based on the file with focus in the editor.</p>
</blockquote>
<p>Uhu... I think that needs some design, but, as a straw man, overrideCommand could contain placeholder like <code>${visibleFiles}</code>, and we can thread that to flycheck. </p>
<p>An imoprtant design point here is that the thing shoudl be based on <strong>state</strong> and not <strong>events</strong>. Communicating "this file changed" would be brittle; Communicating "files <a href="http://x.rs">x.rs</a>, <a href="http://y.rs">y.rs</a>, <a href="http://z.rs">z.rs</a> are opened, go figure which commands should be run to get errors for them" should work better</p>



<a name="207555439"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Parametric%20Flycheck%3F/near/207555439" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> woody77 <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Parametric.20Flycheck.3F.html#207555439">(Aug 20 2020 at 18:12)</a>:</h4>
<p>I'm using Cargo as it's easier to do some prototyping with than our actual build system, as the actual build system is also trying to do a lot more (in other languages as well), and so it's a much heavier process.</p>



<a name="207668777"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Parametric%20Flycheck%3F/near/207668777" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> woody77 <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Parametric.20Flycheck.3F.html#207668777">(Aug 21 2020 at 18:36)</a>:</h4>
<p>So, with some more digging, and it looks like my flycheck script isn't being called at all (I have it writing to a file each time it's called)...  But I have a complicated VSCode Remote setup (and I'm never sure how local and remote VSCode settings interract), so I'm going to simplify to a local-only setup and see what that gets me.</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>